pragma Singleton

import QtQuick

QtObject {
    property var routes : ({})
    property var windows: []
    function addWindow(win){
        if(!win.transientParent){
            windows.push(win)
        }
    }
    function removeWindow(win) {
        if(!win.transientParent){
            var index = windows.indexOf(win)
            if (index !== -1) {
                windows.splice(index, 1)
                win.deleteLater()
            }
        }
    }
    function exit(retCode){
        for(var i =0 ;i< windows.length; i++){
            var win = windows[i]
            win.deleteLater()
        }
        windows = []
        Qt.exit(retCode)
    }
    // function navigate(route,argument={},windowRegister = undefined){
    function navigate(route){
        //检查路由界面是否存在
        if(!routes.hasOwnProperty(route)){
            console.error("Not Found Route",route)
            return
        }
        //创建页面组件
        var windowComponent = Qt.createComponent(routes[route])
        if (windowComponent.status !== Component.Ready) {
            console.error(windowComponent.errorString())
            return
        }

        var properties = {}
        windowComponent.createObject(null,properties)

    }
}
